package com.cdd.agent.api.service;

import com.cdd.common.domain.entity.AgentUser;
import com.cdd.common.domain.entity.AgentUserWithdraw;
import com.cdd.agent.api.mapper.AgentUserMapper;
import com.cdd.agent.api.mapper.AgentUserWithdrawMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author cdd
 * @date 2025-08-08 10:06
 */
@Service
public class AgentUserWithdrawService {

    @Resource
    private AgentUserWithdrawMapper agentUserWithdrawMapper;

    @Resource
    private AgentUserMapper agentUserMapper;

    public AgentUserWithdrawMapper getBaseMapper() {
        return agentUserWithdrawMapper;
    }

    public void withdraw(AgentUserWithdraw param, AgentUser agentUser) {
        agentUser.setMoney(agentUser.getMoney().subtract(param.getMoney()));
        agentUserMapper.updateById(agentUser);
        agentUserWithdrawMapper.insert(param);
    }
}
